package com.danciyixue.boot.client.task.controller;

import com.danciyixue.boot.common.result.Result;
import com.danciyixue.boot.dcyx.model.vo.TaskItemVO;
import com.danciyixue.boot.dcyx.service.TaskAssignmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "学习任务(客户端)")
@RestController
@RequestMapping("/api/client/v1/task")
@RequiredArgsConstructor
public class DcyxTaskController {

    private final TaskAssignmentService taskAssignmentService;

    @Operation(summary = "今日待办任务子项")
    @GetMapping("/today")
    public Result<List<TaskItemVO>> today() {
        return Result.success(taskAssignmentService.getTodayTasksForCurrentStudent());
    }

    @Operation(summary = "登录闸门今日状态")
    @GetMapping("/gate/today/status")
    public Result<Map<String, Boolean>> gateToday() {
        boolean has = taskAssignmentService.hasTodayPendingForCurrentStudent();
        Map<String, Boolean> map = new HashMap<>();
        map.put("hasPending", has);
        return Result.success(map);
    }

    @Operation(summary = "刷新任务子项完成状态")
    @PostMapping("/item/{id}/refresh")
    public Result<Void> refresh(@PathVariable("id") Long id) {
        boolean ok = taskAssignmentService.refreshItemForCurrentStudent(id);
        return Result.judge(ok);
    }
}

